markov.m
Creates the Markov transition matrix
and discrete support
approximating a reflected AR(1) with innovation distribution
Two levels of approximation are involved. First, the innovation distribution is approximated with a mixture of uniform distributions using approximate.m. For each of these mixing uniform distributions, a Markov transition matrix over a finite grid is created. These are averaged using the relevant mixing probabilities to create the Markov transition matrix.
Contents
Set up the problem's parameters
This section first checks to see if the parameters of the problem are defined in the structure markovARG . If this does not exist, then it defines them.
if exist('markovARG','var') %Use values in markovARG if available. %Support parameters: center, stepsize, and width. omegaCenter=markovARG.omegaCenter; omegaStep=markovARG.omegaStep; omegaWidth=markovARG.omegaWidth; %Autocorrelation and standard deviation rho=markovARG.rho; sigma=markovARG.sigma; %Parameters for approximating the innovation distribution. approximateARG=markovARG.approximateARG; else %Defalt values omegaCenter=0.0; omegaStep=0.002; omegaWidth=5; rho=1; sigma=0.295; approximateARG.F=@(x) (1+erf(x/sqrt(2)))./2; approximateARG.Frange=5; approximateARG.k=51; end
Calculate mixing probabilities.
This section calls the script approximate.m.
When finished, the ranges of the mixing distributions are in the vector rangeVec, the mixing probabilities are in the vector mixProb, and the number of mixing distributions is in k.
approximate
Set up state space,
omega=(omegaCenter-0.5*omegaWidth):omegaStep:(omegaCenter+0.5*omegaWidth); nCstates=max(size(omega));
Calculate the Markov transition matrix
where
is the Markov transition matrix associated with the i th mixing distribution.
%Adjust the uniform distributions' ranges. rangeVec=sigma*rangeVec; %Allocate the transition matrix. Pi=zeros(nCstates,nCstates); %Cycle through the mixing probabilities. for i=1:k Pii=zeros(nCstates,nCstates); ri=rangeVec(i); for j=1:nCstates %Calculate the transition probabilities for each state. %Calculate the conditional mean and support of the underlying continuous distribution. rhoC=rho*(omega(j)-omegaCenter)+omegaCenter; lowlim=rhoC-ri; highlim=rhoC+ri; %If the implied support would leave omega, then bounce it back in. if lowlim<omega(1); lowlim=omega(1); highlim=omega(1)+2*ri; elseif highlim>omega(end); lowlim=omega(end)-2*ri; highlim=omega(end); end %Find the states with positive %probability, count them, and set the %appropriate elements of Pii. cindx=find((lowlim<=omega).*(highlim>=omega)); nMoves=max(size(cindx)); Pii(j,cindx)=1/nMoves; end %Multiply Pii by the mixing probability %and add it to Pi. Pi=Pi+mixProb(i)*Pii; end
Plot the transition densities.
if ~exist('markovARG','var') figure(1) set(gcf,'Color',[1 1 1],'Units','inches','Position',[0 0 6 7]) indxvec=1:round(nCstates/11):nCstates; ylimhigh=max(max(Pi)); for i=1:12; subplot(6,2,i) set(gca,'FontSize',16) plot(omega,Pi(indxvec(i),:),'-k','LineWidth',2.5); xlim([omega(1) omega(end)]); ylim([0 ylimhigh]); if i==5; ylabel('Probability'); end set(gca,'XTick',omega(indxvec(i))); set(gca,'XTickLabel',num2str(omega(indxvec(i)),'%2.2f')) set(gca,'YTick',0.0); set(gca,'YTickLabel',' '); if i==11 || i==12 xlabel('ln(C_t)'); end box off; end end

Calculate and plot ergodic distribution.
The ergodic distribuition solves
if ~exist('markovARG','var') [p,d,flag]=eigs(Pi',1); if abs(d-1)>10e-10 || flag~=0 error('Calculation of ergodic distribution failed.') end %Normalize the eigen vector to have unit %length. p=p/sum(p); figure(2) plot(omega,p','-k','LineWidth',2.5) set(gca,'FontSize',16) box off set(gcf,'Color',[1 1 1]); xlim([omega(1) omega(end)]); ylim([0 1.01*max(p)]); ylabel('Probability') xlabel('ln(C_t)') end
Iteration 1: a few Ritz values of the 20-by-20 matrix: 0 0 Iteration 2: a few Ritz values of the 20-by-20 matrix: 0.9745 1.0000
